package a10_动态规划;

import java.util.Arrays;

/**
 * <p>
 * a19_零钱兑换2复习3
 * </p>
 *
 * @author flyduck
 * @since 2025/3/14
 */
public class a19_零钱兑换2复习3 {
    public static void main(String[] args) {
        a19_零钱兑换2复习3 test = new a19_零钱兑换2复习3();
        System.out.println(test.change(5, new int[]{1, 2, 5}));
    }
    //dp[i][j]：从0~i的硬币中簇成amount有dp[i][j]种组合

    //递推公式：
    //不包含i：dp[i-1][j]
    //包含i：dp[i][j-coins[i]]
    //dp[i][j] = dp[i-1][j] + dp[i][j-coins[i]]

    //dp[0][0]~dp[0][amount]
    public int change(int amount, int[] coins) {
        int[] dp = new int[amount+1];
        dp[0] = 1;
        for (int i = 0; i < coins.length; i++) {
            for (int j = 0; j <= amount; j++) {
                if(j >= coins[i]){
                    dp[j] = dp[j]+dp[j-coins[i]];
                }
            }
            System.out.println(Arrays.toString(dp));
        }
        return dp[amount];
    }
}
